<!DOCTYPE html>
<html lang="zh-Hans" dir="ltr">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>IPC 事件驱动 | ENERGY</title>
    
    <meta name="generator" content="VitePress v1.3.4">
    <link rel="preload stylesheet" href="/assets/style.CVmrvE-Z.css" as="style">
    <script type="module" src="/assets/chunks/metadata.704ba9d8.js"></script>
    <script type="module" src="/assets/app.C45ajGbE.js"></script>
    <link rel="preload" href="/assets/inter-roman-latin.Di8DUHzh.woff2" as="font" type="font/woff2" crossorigin="">
    <link rel="modulepreload" href="/assets/chunks/theme.Dj-KnMWw.js">
    <link rel="modulepreload" href="/assets/chunks/framework.D5tr8Gic.js">
    <link rel="modulepreload" href="/assets/document_ipc-event.md.obwNucFQ.lean.js">
    <link rel="icon" href="/imgs/favicon.ico">
    <link rel="icon" type="image/png" href="/imgs/energy.png">
    <meta name="theme-color" content="#5f67ee">
    <meta name="keywords" content="ENERGY,ENERGYGUI,CEF,GOGUI">
    <meta name="description" content="ENERGY是Go基于LCL和CEF(Chromium Embedded Framework)开发的GUI框架, 用于开发Windows、MacOS 和 Linux 跨平台桌面应用">
    <meta property="og:type" content="article">
    <meta property="og:locale" content="cn">
    <meta property="og:title" content="ENERGY文档">
    <meta property="og:description" content="ENERGY是Go基于LCL和CEF(Chromium Embedded Framework)开发的GUI框架, 用于开发Windows、MacOS 和 Linux 跨平台桌面应用">
    <meta property="og:keywords" content="Energy,GoGUI,GolangGUI,桌面应用,跨平台GUI,跨平台桌面应用,开源GUI,GoCEF,GolangCEF,Go桌面应用,Golang桌面应用,Golang构建跨平台应用">
    <meta property="og:site_name" content="Go ENERGY">
    <meta property="google-site-verification" content="y1ft7YSwR6LAzQsR3s2OBajPkbLz16MDC809PgeHYfI">
    <meta property="og:image" content="https://energye.github.io/imgs/energy-277x156.png">
    <meta property="og:url" content="https://energye.github.io">
    <script>window._hmt=window._hmt||[],function(){let e=document.createElement("script");e.src="https://hm.baidu.com/hm.js?5c579ee49a29203cd8dff7fa8eda5ac9";let t=document.getElementsByTagName("script")[0];t.parentNode.insertBefore(e,t)}();</script>
    <script id="check-dark-mode">(()=>{const e=localStorage.getItem("vitepress-theme-appearance")||"dark",a=window.matchMedia("(prefers-color-scheme: dark)").matches;(!e||e==="auto"?a:e==="dark")&&document.documentElement.classList.add("dark")})();</script>
    <script id="check-mac-os">document.documentElement.classList.toggle("mac",/Mac|iPhone|iPod|iPad/i.test(navigator.platform));</script>
  </head>
  <body>
    <div id="app"><div class="Layout" data-v-d8b57b2d><!--[--><!--]--><!--[--><span tabindex="-1" data-v-c8291ffa></span><a href="#VPContent" class="VPSkipLink visually-hidden" data-v-c8291ffa> Skip to content </a><!--]--><!----><header class="VPNav" data-v-d8b57b2d data-v-7ad780c2><div class="VPNavBar has-sidebar top" data-v-7ad780c2 data-v-9fd4d1dd><div class="wrapper" data-v-9fd4d1dd><div class="container" data-v-9fd4d1dd><div class="title" data-v-9fd4d1dd><div class="VPNavBarTitle has-sidebar" data-v-9fd4d1dd data-v-0ad69264><a class="title" href="/" data-v-0ad69264><!--[--><!--]--><!--[--><img class="VPImage logo" src="/imgs/icon.png" width="24" height="24" alt data-v-ab19afbb><!--]--><span data-v-0ad69264>ENERGY</span><!--[--><!--]--></a></div></div><div class="content" data-v-9fd4d1dd><div class="content-body" data-v-9fd4d1dd><!--[--><!--]--><div class="VPNavBarSearch search" data-v-9fd4d1dd><!--[--><!----><div id="local-search"><button type="button" class="DocSearch DocSearch-Button" aria-label="搜索文档"><span class="DocSearch-Button-Container"><span class="vp-icon DocSearch-Search-Icon"></span><span class="DocSearch-Button-Placeholder">搜索文档</span></span><span class="DocSearch-Button-Keys"><kbd class="DocSearch-Button-Key"></kbd><kbd class="DocSearch-Button-Key">K</kbd></span></button></div><!--]--></div><nav aria-labelledby="main-nav-aria-label" class="VPNavBarMenu menu" data-v-9fd4d1dd data-v-afb2845e><span id="main-nav-aria-label" class="visually-hidden" data-v-afb2845e> Main Navigation </span><!--[--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/course/what-is-energy" tabindex="0" data-v-afb2845e data-v-08fbf4b6><!--[--><span data-v-08fbf4b6>教程</span><!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/examples" tabindex="0" data-v-afb2845e data-v-08fbf4b6><!--[--><span data-v-08fbf4b6>示例</span><!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink active" href="/document" tabindex="0" data-v-afb2845e data-v-08fbf4b6><!--[--><span data-v-08fbf4b6>文档</span><!--]--></a><!--]--><!--[--><div class="VPFlyout VPNavBarMenuGroup" data-v-afb2845e data-v-af5898d3><button type="button" class="button" aria-haspopup="true" aria-expanded="false" data-v-af5898d3><span class="text" data-v-af5898d3><!----><span data-v-af5898d3>2.5.6</span><span class="vpi-chevron-down text-icon" data-v-af5898d3></span></span></button><div class="menu" data-v-af5898d3><div class="VPMenu" data-v-af5898d3 data-v-20ed86d6><div class="items" data-v-20ed86d6><!--[--><!--[--><div class="VPMenuLink" data-v-20ed86d6 data-v-f51f088d><a class="VPLink link vp-external-link-icon" href="https://github.com/energye/energy/blob/main/UpdateLog.md" target="_blank" rel="noreferrer" data-v-f51f088d><!--[-->更新日志<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-20ed86d6 data-v-f51f088d><a class="VPLink link vp-external-link-icon" href="https://gitee.com/energye/energy/milestones/196997" target="_blank" rel="noreferrer" data-v-f51f088d><!--[-->版本 3.0<!--]--></a></div><!--]--><!--]--></div><!--[--><!--]--></div></div></div><!--]--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://forum.yanghy.cn" target="_blank" rel="noreferrer" tabindex="0" data-v-afb2845e data-v-08fbf4b6><!--[--><span data-v-08fbf4b6>论坛</span><!--]--></a><!--]--><!--[--><div class="VPFlyout VPNavBarMenuGroup" data-v-afb2845e data-v-af5898d3><button type="button" class="button" aria-haspopup="true" aria-expanded="false" data-v-af5898d3><span class="text" data-v-af5898d3><!----><span data-v-af5898d3>下载</span><span class="vpi-chevron-down text-icon" data-v-af5898d3></span></span></button><div class="menu" data-v-af5898d3><div class="VPMenu" data-v-af5898d3 data-v-20ed86d6><div class="items" data-v-20ed86d6><!--[--><!--[--><div class="VPMenuLink" data-v-20ed86d6 data-v-f51f088d><a class="VPLink link vp-external-link-icon" href="https://sourceforge.net/projects/energye/files/cli/" target="_blank" rel="noreferrer" data-v-f51f088d><!--[-->CLI<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-20ed86d6 data-v-f51f088d><a class="VPLink link vp-external-link-icon" href="https://sourceforge.net/projects/liblcl/files/" target="_blank" rel="noreferrer" data-v-f51f088d><!--[-->CEF &amp; LCL<!--]--></a></div><!--]--><!--]--></div><!--[--><!--]--></div></div></div><!--]--><!--[--><div class="VPFlyout VPNavBarMenuGroup" data-v-afb2845e data-v-af5898d3><button type="button" class="button" aria-haspopup="true" aria-expanded="false" data-v-af5898d3><span class="text" data-v-af5898d3><!----><span data-v-af5898d3>关于</span><span class="vpi-chevron-down text-icon" data-v-af5898d3></span></span></button><div class="menu" data-v-af5898d3><div class="VPMenu" data-v-af5898d3 data-v-20ed86d6><div class="items" data-v-20ed86d6><!--[--><!--[--><div class="VPMenuLink" data-v-20ed86d6 data-v-f51f088d><a class="VPLink link" href="/about/question" data-v-f51f088d><!--[-->常见问题<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-20ed86d6 data-v-f51f088d><a class="VPLink link" href="/about/support" data-v-f51f088d><!--[-->捐赠支持<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-20ed86d6 data-v-f51f088d><a class="VPLink link" href="/about/contact" data-v-f51f088d><!--[-->技术支持<!--]--></a></div><!--]--><!--[--><div class="VPMenuGroup" data-v-20ed86d6 data-v-a6b0397c><p class="title" data-v-a6b0397c>相关项目</p><!--[--><!--[--><div class="VPMenuLink" data-v-a6b0397c data-v-f51f088d><a class="VPLink link vp-external-link-icon" href="https://github.com/energye/energy" target="_blank" rel="noreferrer" data-v-f51f088d><!--[-->Go Energy<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-a6b0397c data-v-f51f088d><a class="VPLink link vp-external-link-icon" href="https://github.com/energye/lcl" target="_blank" rel="noreferrer" data-v-f51f088d><!--[-->LCL<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-a6b0397c data-v-f51f088d><a class="VPLink link vp-external-link-icon" href="https://github.com/energye/cef" target="_blank" rel="noreferrer" data-v-f51f088d><!--[-->CEF<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-a6b0397c data-v-f51f088d><a class="VPLink link vp-external-link-icon" href="https://github.com/energye/wv" target="_blank" rel="noreferrer" data-v-f51f088d><!--[-->WebView<!--]--></a></div><!--]--><!--]--></div><!--]--><!--[--><div class="VPMenuGroup" data-v-20ed86d6 data-v-a6b0397c><p class="title" data-v-a6b0397c>成就认证</p><!--[--><!--[--><div class="VPMenuLink" data-v-a6b0397c data-v-f51f088d><a class="VPLink link" href="/about/honorcert" data-v-f51f088d><!--[-->荣誉证书<!--]--></a></div><!--]--><!--]--></div><!--]--><!--]--></div><!--[--><!--]--></div></div></div><!--]--><!--]--></nav><div class="VPFlyout VPNavBarTranslations translations" data-v-9fd4d1dd data-v-acee064b data-v-af5898d3><button type="button" class="button" aria-haspopup="true" aria-expanded="false" aria-label="多语言" data-v-af5898d3><span class="text" data-v-af5898d3><span class="vpi-languages option-icon" data-v-af5898d3></span><!----><span class="vpi-chevron-down text-icon" data-v-af5898d3></span></span></button><div class="menu" data-v-af5898d3><div class="VPMenu" data-v-af5898d3 data-v-20ed86d6><!----><!--[--><!--[--><div class="items" data-v-acee064b><p class="title" data-v-acee064b>中文</p><!--[--><div class="VPMenuLink" data-v-acee064b data-v-f51f088d><a class="VPLink link" href="/en/document/ipc-event" data-v-f51f088d><!--[-->English<!--]--></a></div><!--]--></div><!--]--><!--]--></div></div></div><div class="VPNavBarAppearance appearance" data-v-9fd4d1dd data-v-3f90c1a5><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="切换到浅色模式" aria-checked="true" data-v-3f90c1a5 data-v-be9742d9 data-v-b4ccac88><span class="check" data-v-b4ccac88><span class="icon" data-v-b4ccac88><!--[--><span class="vpi-sun sun" data-v-be9742d9></span><span class="vpi-moon moon" data-v-be9742d9></span><!--]--></span></span></button></div><div class="VPSocialLinks VPNavBarSocialLinks social-links" data-v-9fd4d1dd data-v-ef6192dc data-v-e71e869c><!--[--><a class="VPSocialLink no-icon" href="https://gitee.com/energye/energy" aria-label target="_blank" rel="noopener" data-v-e71e869c data-v-358b6670><svg t="1730863652667" class="icon" viewBox="0 0 1025 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="4281" width="200" height="200"><path d="M514.275556 512m-510.862223 0a510.862222 510.862222 0 1 0 1021.724445 0 510.862222 510.862222 0 1 0-1021.724445 0Z" fill="#C71D23" p-id="4282"></path><path d="M772.551111 455.111111H483.555556c-13.653333 0-25.031111 11.377778-25.031112 25.031111v62.577778c0 13.653333 11.377778 25.031111 25.031112 25.031111L659.911111 568.888889c13.653333 0 25.031111 11.377778 25.031111 25.031111v13.653333c0 42.097778-34.133333 75.093333-75.093333 75.093334h-238.933333c-13.653333 0-25.031111-11.377778-25.031112-25.031111v-238.933334c0-42.097778 34.133333-75.093333 75.093334-75.093333h352.711111c13.653333 0 25.031111-11.377778 25.031111-25.031111v-62.577778c0-13.653333-11.377778-25.031111-25.031111-25.031111H420.977778c-104.675556 0-188.871111 84.195556-188.871111 188.871111v352.711111c0 13.653333 11.377778 25.031111 25.031111 25.031111h372.053333c94.435556 0 170.666667-76.231111 170.666667-170.666666V480.142222c-1.137778-13.653333-12.515556-25.031111-27.306667-25.031111z" fill="#FFFFFF" p-id="4283"></path></svg></a><a class="VPSocialLink no-icon" href="https://gitcode.com/energye/energy" aria-label target="_blank" rel="noopener" data-v-e71e869c data-v-358b6670><svg width="28" height="28" viewBox="0 0 28 28" fill="none" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M18.059 5.80628C18.2234 5.71425 18.3973 5.61696 18.585 5.51037C18.6076 5.63327 18.6297 5.74058 18.6497 5.83784C18.685 6.00943 18.714 6.15059 18.728 6.29005C18.8392 7.50125 19.448 8.39222 20.3108 8.59286C21.5726 8.88583 22.7623 8.40159 23.4033 7.33318C24.1733 6.05123 23.839 4.4812 22.5279 3.53618C18.8826 0.907049 14.8777 0.18191 10.5636 1.44819C1.2616 4.1927 -1.92121 15.6199 4.68062 22.6274C7.50507 25.6249 11.0914 26.9182 15.1624 26.8204C20.3774 26.6979 24.1333 24.099 26.5309 19.5947C28.2308 16.3988 26.3829 12.9055 22.8439 12.1795C20.8227 11.7726 18.7559 11.6405 16.6993 11.7869C16.0151 11.8526 15.3509 12.0547 14.7459 12.3811C14.0691 12.7324 13.8734 13.4614 13.9493 14.1838C14.02 14.8421 14.5247 15.2369 15.1258 15.3362C16.3361 15.5256 17.5609 15.6357 18.7833 15.7361C19.1371 15.7659 19.4942 15.7694 19.8507 15.773C20.3623 15.7781 20.873 15.7832 21.3718 15.8657C22.7949 16.1009 23.2836 17.2557 22.5517 18.4911C22.3724 18.7882 22.1633 19.0662 21.9277 19.3209C20.9703 20.3738 19.7183 21.1144 18.3344 21.4465C15.8084 22.0649 13.2798 22.0996 10.7655 21.3054C7.90238 20.4021 6.19549 18.2991 6.13552 15.4682C6.1131 13.7223 6.55634 12.002 7.41963 10.4843C7.80967 9.77685 8.02376 9.04827 7.96359 8.24664C7.93826 7.90488 7.92423 7.56273 7.90915 7.19506C7.90113 6.99938 7.89281 6.79647 7.88233 6.58254C8.17231 6.6434 8.45871 6.72023 8.74022 6.81271C9.83531 7.2523 10.9132 7.45284 12.0986 7.13019C12.7728 6.96895 13.4697 6.92433 14.159 6.99829C15.269 7.08878 16.3785 6.81759 17.3215 6.22521C17.5569 6.08724 17.7963 5.9533 18.059 5.80628Z" fill="#DA203E"/></svg></a><a class="VPSocialLink no-icon" href="https://github.com/energye/energy" aria-label="github" target="_blank" rel="noopener" data-v-e71e869c data-v-358b6670><span class="vpi-social-github" /></a><!--]--></div><div class="VPFlyout VPNavBarExtra extra" data-v-9fd4d1dd data-v-f953d92f data-v-af5898d3><button type="button" class="button" aria-haspopup="true" aria-expanded="false" aria-label="extra navigation" data-v-af5898d3><span class="vpi-more-horizontal icon" data-v-af5898d3></span></button><div class="menu" data-v-af5898d3><div class="VPMenu" data-v-af5898d3 data-v-20ed86d6><!----><!--[--><!--[--><div class="group translations" data-v-f953d92f><p class="trans-title" data-v-f953d92f>中文</p><!--[--><div class="VPMenuLink" data-v-f953d92f data-v-f51f088d><a class="VPLink link" href="/en/document/ipc-event" data-v-f51f088d><!--[-->English<!--]--></a></div><!--]--></div><div class="group" data-v-f953d92f><div class="item appearance" data-v-f953d92f><p class="label" data-v-f953d92f>主题</p><div class="appearance-action" data-v-f953d92f><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="切换到浅色模式" aria-checked="true" data-v-f953d92f data-v-be9742d9 data-v-b4ccac88><span class="check" data-v-b4ccac88><span class="icon" data-v-b4ccac88><!--[--><span class="vpi-sun sun" data-v-be9742d9></span><span class="vpi-moon moon" data-v-be9742d9></span><!--]--></span></span></button></div></div></div><div class="group" data-v-f953d92f><div class="item social-links" data-v-f953d92f><div class="VPSocialLinks social-links-list" data-v-f953d92f data-v-e71e869c><!--[--><a class="VPSocialLink no-icon" href="https://gitee.com/energye/energy" aria-label target="_blank" rel="noopener" data-v-e71e869c data-v-358b6670><svg t="1730863652667" class="icon" viewBox="0 0 1025 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="4281" width="200" height="200"><path d="M514.275556 512m-510.862223 0a510.862222 510.862222 0 1 0 1021.724445 0 510.862222 510.862222 0 1 0-1021.724445 0Z" fill="#C71D23" p-id="4282"></path><path d="M772.551111 455.111111H483.555556c-13.653333 0-25.031111 11.377778-25.031112 25.031111v62.577778c0 13.653333 11.377778 25.031111 25.031112 25.031111L659.911111 568.888889c13.653333 0 25.031111 11.377778 25.031111 25.031111v13.653333c0 42.097778-34.133333 75.093333-75.093333 75.093334h-238.933333c-13.653333 0-25.031111-11.377778-25.031112-25.031111v-238.933334c0-42.097778 34.133333-75.093333 75.093334-75.093333h352.711111c13.653333 0 25.031111-11.377778 25.031111-25.031111v-62.577778c0-13.653333-11.377778-25.031111-25.031111-25.031111H420.977778c-104.675556 0-188.871111 84.195556-188.871111 188.871111v352.711111c0 13.653333 11.377778 25.031111 25.031111 25.031111h372.053333c94.435556 0 170.666667-76.231111 170.666667-170.666666V480.142222c-1.137778-13.653333-12.515556-25.031111-27.306667-25.031111z" fill="#FFFFFF" p-id="4283"></path></svg></a><a class="VPSocialLink no-icon" href="https://gitcode.com/energye/energy" aria-label target="_blank" rel="noopener" data-v-e71e869c data-v-358b6670><svg width="28" height="28" viewBox="0 0 28 28" fill="none" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M18.059 5.80628C18.2234 5.71425 18.3973 5.61696 18.585 5.51037C18.6076 5.63327 18.6297 5.74058 18.6497 5.83784C18.685 6.00943 18.714 6.15059 18.728 6.29005C18.8392 7.50125 19.448 8.39222 20.3108 8.59286C21.5726 8.88583 22.7623 8.40159 23.4033 7.33318C24.1733 6.05123 23.839 4.4812 22.5279 3.53618C18.8826 0.907049 14.8777 0.18191 10.5636 1.44819C1.2616 4.1927 -1.92121 15.6199 4.68062 22.6274C7.50507 25.6249 11.0914 26.9182 15.1624 26.8204C20.3774 26.6979 24.1333 24.099 26.5309 19.5947C28.2308 16.3988 26.3829 12.9055 22.8439 12.1795C20.8227 11.7726 18.7559 11.6405 16.6993 11.7869C16.0151 11.8526 15.3509 12.0547 14.7459 12.3811C14.0691 12.7324 13.8734 13.4614 13.9493 14.1838C14.02 14.8421 14.5247 15.2369 15.1258 15.3362C16.3361 15.5256 17.5609 15.6357 18.7833 15.7361C19.1371 15.7659 19.4942 15.7694 19.8507 15.773C20.3623 15.7781 20.873 15.7832 21.3718 15.8657C22.7949 16.1009 23.2836 17.2557 22.5517 18.4911C22.3724 18.7882 22.1633 19.0662 21.9277 19.3209C20.9703 20.3738 19.7183 21.1144 18.3344 21.4465C15.8084 22.0649 13.2798 22.0996 10.7655 21.3054C7.90238 20.4021 6.19549 18.2991 6.13552 15.4682C6.1131 13.7223 6.55634 12.002 7.41963 10.4843C7.80967 9.77685 8.02376 9.04827 7.96359 8.24664C7.93826 7.90488 7.92423 7.56273 7.90915 7.19506C7.90113 6.99938 7.89281 6.79647 7.88233 6.58254C8.17231 6.6434 8.45871 6.72023 8.74022 6.81271C9.83531 7.2523 10.9132 7.45284 12.0986 7.13019C12.7728 6.96895 13.4697 6.92433 14.159 6.99829C15.269 7.08878 16.3785 6.81759 17.3215 6.22521C17.5569 6.08724 17.7963 5.9533 18.059 5.80628Z" fill="#DA203E"/></svg></a><a class="VPSocialLink no-icon" href="https://github.com/energye/energy" aria-label="github" target="_blank" rel="noopener" data-v-e71e869c data-v-358b6670><span class="vpi-social-github" /></a><!--]--></div></div></div><!--]--><!--]--></div></div></div><!--[--><!--]--><button type="button" class="VPNavBarHamburger hamburger" aria-label="mobile navigation" aria-expanded="false" aria-controls="VPNavScreen" data-v-9fd4d1dd data-v-6bee1efd><span class="container" data-v-6bee1efd><span class="top" data-v-6bee1efd></span><span class="middle" data-v-6bee1efd></span><span class="bottom" data-v-6bee1efd></span></span></button></div></div></div></div><div class="divider" data-v-9fd4d1dd><div class="divider-line" data-v-9fd4d1dd></div></div></div><!----></header><div class="VPLocalNav has-sidebar empty" data-v-d8b57b2d data-v-2488c25a><div class="container" data-v-2488c25a><button class="menu" aria-expanded="false" aria-controls="VPSidebarNav" data-v-2488c25a><span class="vpi-align-left menu-icon" data-v-2488c25a></span><span class="menu-text" data-v-2488c25a>菜单</span></button><div class="VPLocalNavOutlineDropdown" style="--vp-vh:0px;" data-v-2488c25a data-v-883964e0><button data-v-883964e0>返回顶部</button><!----></div></div></div><aside class="VPSidebar" data-v-d8b57b2d data-v-42c4c606><div class="curtain" data-v-42c4c606></div><nav class="nav" id="VPSidebarNav" aria-labelledby="sidebar-aria-label" tabindex="-1" data-v-42c4c606><span class="visually-hidden" id="sidebar-aria-label" data-v-42c4c606> Sidebar Navigation </span><!--[--><!--]--><!--[--><div class="no-transition group" data-v-51288d80><section class="VPSidebarItem level-0 has-active" data-v-51288d80 data-v-edd2eed8><div class="item" role="button" tabindex="0" data-v-edd2eed8><div class="indicator" data-v-edd2eed8></div><h2 class="text" data-v-edd2eed8>文档</h2><!----></div><div class="items" data-v-edd2eed8><!--[--><div class="VPSidebarItem level-1 is-link" data-v-edd2eed8 data-v-edd2eed8><div class="item" data-v-edd2eed8><div class="indicator" data-v-edd2eed8></div><a class="VPLink link link" href="/document/application" data-v-edd2eed8><!--[--><p class="text" data-v-edd2eed8>Application</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-edd2eed8 data-v-edd2eed8><div class="item" data-v-edd2eed8><div class="indicator" data-v-edd2eed8></div><a class="VPLink link link" href="/document/ipc-event" data-v-edd2eed8><!--[--><p class="text" data-v-edd2eed8>IPC Event</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="no-transition group" data-v-51288d80><section class="VPSidebarItem level-0" data-v-51288d80 data-v-edd2eed8><!----><div class="items" data-v-edd2eed8><!--[--><div class="VPSidebarItem level-1 is-link" data-v-edd2eed8 data-v-edd2eed8><div class="item" data-v-edd2eed8><div class="indicator" data-v-edd2eed8></div><a class="VPLink link link" href="/document/version-upgrade-releases" data-v-edd2eed8><!--[--><p class="text" data-v-edd2eed8>版本升级</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-edd2eed8 data-v-edd2eed8><div class="item" data-v-edd2eed8><div class="indicator" data-v-edd2eed8></div><a class="VPLink link link" href="/document/version-details" data-v-edd2eed8><!--[--><p class="text" data-v-edd2eed8>系统架构支持</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-edd2eed8 data-v-edd2eed8><div class="item" data-v-edd2eed8><div class="indicator" data-v-edd2eed8></div><a class="VPLink link link" href="/document/lazarus_lcl" data-v-edd2eed8><!--[--><p class="text" data-v-edd2eed8>LCL 文档链接</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><!--]--><!--[--><!--]--></nav></aside><div class="VPContent has-sidebar" id="VPContent" data-v-d8b57b2d data-v-9a6c75ad><div class="VPDoc has-sidebar has-aside" data-v-9a6c75ad data-v-e6f2a212><!--[--><!--]--><div class="container" data-v-e6f2a212><div class="aside" data-v-e6f2a212><div class="aside-curtain" data-v-e6f2a212></div><div class="aside-container" data-v-e6f2a212><div class="aside-content" data-v-e6f2a212><div class="VPDocAside" data-v-e6f2a212 data-v-cb998dce><!--[--><!--]--><!--[--><!--]--><nav aria-labelledby="doc-outline-aria-label" class="VPDocAsideOutline" data-v-cb998dce data-v-f610f197><div class="content" data-v-f610f197><div class="outline-marker" data-v-f610f197></div><div aria-level="2" class="outline-title" id="doc-outline-aria-label" role="heading" data-v-f610f197>目录</div><ul class="VPDocOutlineItem root" data-v-f610f197 data-v-53c99d69><!--[--><!--]--></ul></div></nav><!--[--><!--]--><div class="spacer" data-v-cb998dce></div><!--[--><!--]--><!----><!--[--><!--]--><!--[--><!--]--></div></div></div></div><div class="content" data-v-e6f2a212><div class="content-container" data-v-e6f2a212><!--[--><!--]--><main class="main" data-v-e6f2a212><div style="position:relative;" class="vp-doc _document_ipc-event" data-v-e6f2a212><div><h1 id="ipc-事件驱动" tabindex="-1">IPC 事件驱动 <a class="header-anchor" href="#ipc-事件驱动" aria-label="Permalink to &quot;IPC 事件驱动&quot;">​</a></h1><h3 id="ipc-事件" tabindex="-1">IPC 事件 <a class="header-anchor" href="#ipc-事件" aria-label="Permalink to &quot;IPC 事件&quot;">​</a></h3><p>它是基于<code>CEF进程消息</code>和<code>Go自定义协议</code>组合实现</p><ul><li><p>CEF进程消息: Application 和 Chromium 的 <code>OnProcessMessageReceived</code> 事件</p></li><li><p>Application 处理渲染进程消息</p></li><li><p>Chromium 处理主进程消息</p></li><li><p>Go自定义协议: 在Go与Go代码之间消息传递时使用</p></li></ul><p>在 Application <code>OnContextCreated</code> 事件执行时注入 <code>ipc</code> JavaScript 对象到浏览器, 它绑定了 <code>on</code> 和 <code>emit</code> 函数, 在每一个浏览器创建后都会注入<code>ipc</code></p><h3 id="使用方式" tabindex="-1">使用方式 <a class="header-anchor" href="#使用方式" aria-label="Permalink to &quot;使用方式&quot;">​</a></h3><h4 id="在go中定义事件" tabindex="-1">在Go中定义事件 <a class="header-anchor" href="#在go中定义事件" aria-label="Permalink to &quot;在Go中定义事件&quot;">​</a></h4><p>使用 <code>ipc.On(name string, fn interface{}, options ...types.OnOptions)</code> 注册监听一个事件</p><ul><li>name: 事件名</li><li>fn: 回调函数, 该事件被触发时执行的函数</li><li>options: 监听选项, 它提供了2种监听模式，和3种监听类型</li></ul><h5 id="fn-回调函数" tabindex="-1">fn 回调函数 <a class="header-anchor" href="#fn-回调函数" aria-label="Permalink to &quot;fn 回调函数&quot;">​</a></h5><p>它可以接收参数和返回数据. 提供了几种自动识别的参数类型。</p><ol><li>context.IContext: 当前事件被执行时原始的事件上下文，在这里可以直接取事件信息</li></ol><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// IContext</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">//	Inter process IPC communication callback context</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">type</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> IContext</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> interface</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">	ArgumentList</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() </span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">json</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">JSONArray</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> //ArgumentList</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">	BrowserId</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int32</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">             //Event ownership: browser id</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">	FrameId</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int64</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">               //Event ownership: frame id</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">	Replay</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() </span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">IReplay</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">              //Replay, When the trigger event returns IContext, this field is nil</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">	Result</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">data</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> ...interface</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">{})   </span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">//callback function return Result</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre></div><ol start="2"><li>callback.IChannel: 当前事件被执行时, 该参数类型可自动识别当前事件是从哪一个浏览器触发, 它可以拿到指定的<code>BrowserId</code>和<code>ChannelId</code></li></ol><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// IChannel</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">//</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">//	The channel ID of the parameter type callback function</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">//	Used for listening to events and receiving parameters from the event channel source</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">type</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> IChannel</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> interface</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">	BrowserId</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int32</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> //Receive Browser Window ID</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">	ChannelId</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int64</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> //Receive Channel ID</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre></div><ol start="3"><li>Go和JS的基础和复合类型对应 常用的基础类型和结构</li></ol><h5 id="options-监听选项" tabindex="-1">options 监听选项 <a class="header-anchor" href="#options-监听选项" aria-label="Permalink to &quot;options 监听选项&quot;">​</a></h5><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// OnOptions Listening options</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">type</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> OnOptions</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> struct</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">	OnType </span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">OnType</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // Listening type, default main process</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">	Mode   </span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">Mode</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">   // IPC emit mode of the browser process</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre></div><h5 id="监听选项-监听类型" tabindex="-1">监听选项-监听类型 <a class="header-anchor" href="#监听选项-监听类型" aria-label="Permalink to &quot;监听选项-监听类型&quot;">​</a></h5><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// OnType listening type</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">type</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> OnType</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int8</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">const</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">	OtMain </span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">OnType</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> iota</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // Only the main process</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">	OtSub                </span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// Only the sub process</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">	OtAll                </span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// All process</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span></code></pre></div><h5 id="监听选项-监听模式" tabindex="-1">监听选项-监听模式 <a class="header-anchor" href="#监听选项-监听模式" aria-label="Permalink to &quot;监听选项-监听模式&quot;">​</a></h5><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// Mode IPC mode of the browser process</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">type</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> Mode</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int8</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">const</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">	// MSync Synchronization, the default way CEF is used</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">	//  In JS, ipc.emit triggers the Go event and processes long-term tasks. The window will remain frozen until the task processing is completed.</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">	MSync </span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">Mode</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> iota</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">	// MAsync</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">	//  Asynchronous, using coroutines, coroutines (within the event) cannot be debugged, there are no other unforeseen problems found so far.</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">	//  异步 (Asynchronous): Refers to an approach where operations can continue without waiting for the previous operations&#39; completion.</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">	//  使用协程 (using coroutines): Indicates the implementation or employment of coroutines, which are a way to manage the execution flow in a non-preemptive manner.</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">	//  协程(事件内)无法Debug (coroutines (within the event) cannot be debugged): Points out the inability to debug coroutines when they are inside an event.</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">	//  暂未发现其它无法预料的问题 (there are no other unforeseen problems found so far): Indicates that, at the time of the statement, no other unforeseen issues have been encountered or identified.</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">	//</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">	// 使用场景 (Usage scenarios):</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">	//</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">	//  Only applicable when using JS ipc.emit to trigger events.</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">	//  Recommended for use in the Go UI main thread when performing long-duration tasks, otherwise it will freeze the UI window.</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">	MAsync</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span></code></pre></div><h4 id="在js中定义事件" tabindex="-1">在JS中定义事件 <a class="header-anchor" href="#在js中定义事件" aria-label="Permalink to &quot;在JS中定义事件&quot;">​</a></h4><p>使用 <code>ipc.on(name: string, fn: function)</code> 注册监听一个事件</p><ul><li>name: 事件名</li><li>fn: 回调函数, 该事件被触发时执行的函数</li></ul><h5 id="fn-回调函数-1" tabindex="-1">fn 回调函数 <a class="header-anchor" href="#fn-回调函数-1" aria-label="Permalink to &quot;fn 回调函数&quot;">​</a></h5><p>它可以接收参数和返回数据. 参数类型为常用的基础类型和复合类型(JSON or Array)</p><h4 id="在go中触发js事件" tabindex="-1">在Go中触发JS事件 <a class="header-anchor" href="#在go中触发js事件" aria-label="Permalink to &quot;在Go中触发JS事件&quot;">​</a></h4><p>在Go有4种触发方式, 都是异步执行, 默认触发主浏览器</p><ul><li><code>ipc.Emit(name string, argument ...interface{}) bool</code></li><li><code>ipc.EmitAndCallback(name string, argument []interface{}, callback interface{}) bool</code></li><li><code>ipc.EmitTarget(name string, target target.ITarget, argument ...interface{}) bool</code></li><li><code>ipc.EmitTargetAndCallback(name string, target target.ITarget, argument []interface{}, callback interface{}) bool</code></li></ul><h5 id="参数" tabindex="-1">参数 <a class="header-anchor" href="#参数" aria-label="Permalink to &quot;参数&quot;">​</a></h5><ul><li>name: JS监听的事件名</li><li>argument: JS监听的回调函数参数，需要注意参数类型</li><li>callback: 触发回调函数，在JS里如果有返回值可通过该函数获取, 该函数没有返回值</li><li>target: 触发事件接收目标, 接口类型, 当事件触发目标不是主浏览器时，通过该参数将事件触发给指定浏览器</li></ul><h6 id="itarget" tabindex="-1">ITarget <a class="header-anchor" href="#itarget" aria-label="Permalink to &quot;ITarget&quot;">​</a></h6><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// ITarget</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">//</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// ipc.NewTarget() *Target</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">type</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> ITarget</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> interface</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">	BrowserId</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int32</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // Browser Window ID</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">	ChannelId</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int64</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // IPC channelID, frameId or GO IPC channelID</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">	TargetType</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() </span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">Type</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // Target type default 0: Trigger JS event</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">	Window</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() </span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">IWindow</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">  // Send IPC Chromium</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre></div><p>它有几个已实现接口结构 -. LCLBrowserWindow -. ViewsFrameworkBrowserWindow -. TCEFChromium -. ICefFrame 除此之外还可以通过已实现的结构 <code>Target(targetType ...target.Type)</code> 函数定义接收类型.</p><p>ITarget 它可以控制事件消息发送位置</p><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// Type</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">//</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">//	0: Trigger the JS event of the specified target process</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">//	1: Trigger TgGoSub events for the specified target sub process</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">//	2: Trigger TgGoMain events for the specified target main process</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">type</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> Type</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int8</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">const</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">	TgJs     </span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">Type</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> iota</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> //JS Event</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">	TgGoSub              </span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">//GO Event sub</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">	TgGoMain             </span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">//GO Event main</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span></code></pre></div><div class="language-go vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">go</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"></span></code></pre></div><h4 id="在js中触发go事件" tabindex="-1">在JS中触发Go事件 <a class="header-anchor" href="#在js中触发go事件" aria-label="Permalink to &quot;在JS中触发Go事件&quot;">​</a></h4><p>有2种方式</p><ul><li><code>ipc.emit(name, argument: array, callback: function)</code></li><li><code>ipc.emit({name:string, arguments: array, callback: function, mode: int, target: int})</code></li></ul><h5 id="参数-1" tabindex="-1">参数 <a class="header-anchor" href="#参数-1" aria-label="Permalink to &quot;参数&quot;">​</a></h5><ul><li>name: 被触发事件名</li><li>argument: 可选，要传递的参数</li><li>callback: 可选，触发后回调函数，它可接收Go的返回值</li><li>mode: 可选，触发模式</li></ul><div class="language-text vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">text</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>0: 异步 </span></span>
<span class="line"><span>1: 同步</span></span>
<span class="line"><span>default 0</span></span></code></pre></div><ul><li>target: 可选，触发接收目标，需要和Go的监听配合使用，默认是主进程</li></ul><div class="language-text vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">text</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>0: 主进程 </span></span>
<span class="line"><span>1: 当前进程</span></span>
<span class="line"><span>2: 其它进程(需要主进程)</span></span>
<span class="line"><span>default 0</span></span></code></pre></div><div class="language-js vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">js</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">let</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> userData </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;key1&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:{</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;Name&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;张三1&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;Age&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">66</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;Income&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">99988.0009</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;Sex&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span><span style="--shiki-light:#005CC5;--shiki-dark:#E1E4E8;">true</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#032F62;--shiki-dark:#E1E4E8;">&quot;UserInfo&quot;:{&quot;Addr&quot;:&quot;addr&quot;,&quot;HeadPicture&quot;:&quot;https://www.demo.com/head.png&quot;,&quot;Height&quot;:800,&quot;Weight&quot;:800,&quot;Phone&quot;:&quot;888-999-000&quot;}},&quot;zhangsan-2&quot;:{&quot;Sex&quot;:true,&quot;UserInfo&quot;:{&quot;HeadPicture&quot;:&quot;https://www.demo.com/head.png&quot;,&quot;Height&quot;:800,&quot;Weight&quot;:800,&quot;Phone&quot;:&quot;888-999-000&quot;,&quot;Addr&quot;:&quot;银河系-猎户座旋臂(离中心远,离边缘近)-太阳系第三环总体位置,离银棒(中心)&quot;},&quot;Name&quot;:&quot;张三2&quot;,&quot;Age&quot;:66,&quot;Income&quot;:99988.0009},&quot;zhangsan-3&quot;:{&quot;Sex&quot;:true,&quot;UserInfo&quot;:{&quot;Addr&quot;:&quot;银河系-猎户座旋臂(离中心远,离边缘近)-太阳系第三环总体位置,离银棒(中心)&quot;,&quot;HeadPicture&quot;:&quot;https://www.demo.com/head.png&quot;,&quot;Height&quot;:800,&quot;Weight&quot;:800,&quot;Phone&quot;:&quot;888-999-000&quot;},&quot;Name&quot;:&quot;张三3&quot;,&quot;Age&quot;:66,&quot;Income&quot;:99988.0009}}</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#E1E4E8;">ipc.</span><span style="--shiki-light:#032F62;--shiki-dark:#B392F0;">emit</span><span style="--shiki-light:#032F62;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;setUserInfo&#39;</span><span style="--shiki-light:#032F62;--shiki-dark:#E1E4E8;">, [userData], </span><span style="--shiki-light:#032F62;--shiki-dark:#F97583;">function</span><span style="--shiki-light:#032F62;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#032F62;--shiki-dark:#FFAB70;">data</span><span style="--shiki-light:#032F62;--shiki-dark:#E1E4E8;">) </span><span style="--shiki-light:#B31D28;--shiki-dark:#E1E4E8;--shiki-light-font-style:italic;--shiki-dark-font-style:inherit;">{</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">   </span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">})</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">ipc.</span><span style="--shiki-light:#24292E;--shiki-dark:#B392F0;">emit</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">({</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">    name: </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;name&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">    arguments: [</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;energy&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">], </span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">    callback</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">function</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">data</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) { </span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">       </span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">    },</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">    mode: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">    target: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">})</span></span></code></pre></div></div></div></main><footer class="VPDocFooter" data-v-e6f2a212 data-v-1bcd8184><!--[--><!--]--><div class="edit-info" data-v-1bcd8184><div class="edit-link" data-v-1bcd8184><a class="VPLink link vp-external-link-icon no-icon edit-link-button" href="https://github.com/energye/energye.github.io/tree/main/zh/document/ipc-event.md" target="_blank" rel="noreferrer" data-v-1bcd8184><!--[--><span class="vpi-square-pen edit-link-icon" data-v-1bcd8184></span> 在 GitHub 上编辑此页面<!--]--></a></div><div class="last-updated" data-v-1bcd8184><p class="VPLastUpdated" data-v-1bcd8184 data-v-1bb0c8a8>上次更新: <time datetime="2024-09-18T09:32:33.000Z" data-v-1bb0c8a8></time></p></div></div><nav class="prev-next" aria-labelledby="doc-footer-aria-label" data-v-1bcd8184><span class="visually-hidden" id="doc-footer-aria-label" data-v-1bcd8184>Pager</span><div class="pager" data-v-1bcd8184><a class="VPLink link pager-link prev" href="/document/application" data-v-1bcd8184><!--[--><span class="desc" data-v-1bcd8184>上一页</span><span class="title" data-v-1bcd8184>Application</span><!--]--></a></div><div class="pager" data-v-1bcd8184><a class="VPLink link pager-link next" href="/document/version-upgrade-releases" data-v-1bcd8184><!--[--><span class="desc" data-v-1bcd8184>下一页</span><span class="title" data-v-1bcd8184>版本升级</span><!--]--></a></div></nav></footer><!--[--><!--]--></div></div></div><!--[--><!--]--></div></div><footer class="VPFooter has-sidebar" data-v-d8b57b2d data-v-566314d4><div class="container" data-v-566314d4><p class="message" data-v-566314d4><span style="color: #2ba9f1;">GO<br>ENERGY</span></p><p class="copyright" data-v-566314d4>Copyright © 2022-2025 YangHY</p></div></footer><!--[--><!--]--></div></div>
    
    
  </body>
</html>